<%@ page language="java" import="java.util.*,ms.platform.system.model.*" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE html>
<html>
<head>
<title>添加角色</title>
<base href="<%=basePath%>">
<link rel="stylesheet" type="text/css" href="<%=basePath%>js/bootstrap-3.3.6/dist/css/bootstrap.min.css">
<link rel="stylesheet" type="text/css" href="<%=basePath%>css/bootstrapValidator.css" />
<link rel="stylesheet" type="text/css" href="<%=basePath%>css/mydialog.css" />
<link rel="stylesheet" type="text/css" href="<%=basePath%>css/style.css" />
</head>
<body>
	<div id="index-hav2">
		<div class="index-hav-right" id="index-hav-right-clear">
			<div class="row">
				<div class="col-md-9">
					<span id="icon-house"> </span><span id="arrows-left">首页</span> <span
						id="arrows-left">></span><span>系统管理</span> <span id="arrows-left">></span><span>角色管理</span>
				</div>
				<div class="bank-box">
					<div class="lianlian platform">
						<div class="col-md-12" style="margin: 13px 0">
							<form id="defaultForm" class="form-horizontal" method="post" action="<%=path%>/system/role/save">
								<div class="panel panel-default">
									<!--  div class="panel-heading">
										<h4 class="panel-title"></h4>
									</div-->
									<div class="panel-body">
										<div class="form-group">
											<label class="col-sm-2 control-label">角色名称:</label>
											<div class="col-sm-6">
												<input type="text" name="roleName" class="form-control" value="">
											</div>
										</div>
										<div class="form-group">
											<label class="col-sm-2 control-label">角色类型:</label>
											<div class="col-sm-6">
												<select class="form-control input-sm mb15" name="type">
													<option value="">-- 请选择 --</option>
													<option value="1">管理员</option>
													<option value="2">普通用户</option>
												</select>
											</div>
										</div>
										<div class="form-group">
											<label class="col-sm-2 control-label">状态:</label>
											<div class="col-sm-6">
												<select class="form-control input-sm mb15" name="isUsed">
													<option value="">-- 请选择 --</option>
													<option value="1">启用</option>
													<option value="0">禁用</option>
												</select>
											</div>
										</div>
										<div class="col-sm-8 col-btn-12">
											<button type="submit" class="btn btn-primary" id="editRoleBtn">保存</button>
											<!--button type="button" class="clearForm btn btn-default">重置</button>  -->
											<button type="button" class="btn btn-default" onclick="window.location.href='<%=path%>/system/role/list'">返回</button>
										</div>	
									</div>
									
								</div>
							</form>

						</div>
					</div>

				</div>
			</div>
		</div>
	</div>
	<div id="gray-screen"></div>
</body>
<script type="text/javascript" src="<%=basePath%>js/validate/jquery-1.10.2.min.js" ></script>
<script type="text/javascript" src="<%=basePath%>js/rem.js" charset="utf-8"></script>
<script type="text/javascript" src="<%=basePath%>js/validate/bootstrapValidator.js"></script>
<script type="text/javascript" src="<%=basePath%>js/validate/zh_CN.js"></script>
<script type="text/javascript" src="<%=basePath%>js/bootstrap-3.3.6/dist/js/bootstrap.min.js" charset="utf-8"></script>
<script type="text/javascript" src="<%=basePath%>js/common/dialog.3.1.min.js"></script>
    <script type="text/javascript">
	$(document).ready(function() {
    $('#defaultForm').bootstrapValidator({
            message: 'This value is not valid',
            feedbackIcons: {
                valid: 'glyphicon glyphicon-ok',
                invalid: 'glyphicon glyphicon-remove',
                validating: 'glyphicon glyphicon-refresh'
            },
            fields: {
            	roleName: {
                    validators: {
                        notEmpty: {},
                        stringLength: {min: 1,max: 30},
                        remote: {
                            type: 'POST',
                        	url: '<%=path%>/system/role/getRoleByName',
                        	message: '该角色名称已存在,不可用',
                        	delay: 1000
                        },
                    }
                },
                type: {
                    validators: {
                        notEmpty: {}
                    }
                },
                isUsed: {
                    validators: {
                        notEmpty: {}
                    }
                },
            }
        }).on('success.form.bv', function(e) {
            // Prevent form submission
            e.preventDefault();

            // Get the form instance
            var $form = $(e.target);

            // Get the BootstrapValidator instance
            var bv = $form.data('bootstrapValidator');

            // Use Ajax to submit form data
            $.post($form.attr('action'), $form.serialize(), function(result) {
            	var grayScreen=document.getElementById("gray-screen"); 
            	Dialog({
		                "msg": '<div class="D_alert">'+result.message+'</div>',
		                "title": "提示",
		                "showButtons": true,
		                "cancelButton": false,
		                "onComplete": function() {
		                 	$("body").empty();
							window.location.href='<%=path%>/system/role/list';
		                }
		            });	 
            }, 'json');
        });
});
</script>
</html>